﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SharedGenomics.Core;
using SharedGenomics.Workbench.Core;
using SharedGenomics.Workbench.Models;

namespace SharedGenomics.Workbench.Views.WindowsForms
{
    public partial class DataFilterResultsView : View, IDataFilterResultsView
    {
        public DataFilterResultsView()
        {
            InitializeComponent();

            this.btSnpsRemoved.CheckedChanged += (o, e) => { this.ShowSnpsChanged.Raise(this); };
            this.btIndividualsRemoved.CheckedChanged += (o, e) => { this.ShowIndividualsChanged.Raise(this); };
        }

        [Region("WatchList")]
        public Panel WatchListPanel
        {
            get { return this.spcWatchList.Panel1; }
        }

        public IDataFilterResultsModel Model
        {
            set
            {
                value.ThrowIfNull("model");
                this.filteredItemsBindingSource.DataSource = value;
                value.ItemsChanged += (sender, e) => { this.UpdateViewFromModel((IDataFilterResultsModel)sender); };
                this.UpdateViewFromModel(value);
            }
        }

        private void UpdateViewFromModel(IDataFilterResultsModel model)
        {
            this.btIndividualsRemoved.Text = String.Format("{0} Individuals removed", model.IndividualCount);
            this.btSnpsRemoved.Text = String.Format("{0} watched SNPs removed", model.SnpCount);
        }

        public bool ShowSnps
        {
            get { return this.btSnpsRemoved.Checked; }
            set { this.btSnpsRemoved.Checked = value; }
        }

        public bool ShowIndividuals
        {
            get { return this.btIndividualsRemoved.Checked; }
            set { this.btIndividualsRemoved.Checked = value; }
        }

        public event EventHandler ShowSnpsChanged;
        public event EventHandler ShowIndividualsChanged;

        public string RemovalReason
        {
            set { this.txtRemovalReason.Text = value; }
        }

        public string RemovalValue
        {
            set { this.txtRemovalValue.Text = value; }
        }

        public string RemainingIndividualCount
        {
            set { this.txtIndividualCountPostFilter.Text = value; }
        }

        public string RemainingSnpCount
        {
            set { this.txtSnpCountPostFiltering.Text = value; }
        }
    }
}
